﻿using AutoMapper;
using danreng.Domain;
using sharp_net;
using sharp_net.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using sharp_net.Repositories.MongoDB;
using Microsoft.Practices.Unity;
using danreng.Enum;
using System.Web.Mvc;
using sharp_net.Mvc;

namespace danreng.Application {
    public abstract class BaseApplication {

        public static void Initialize() {
            MongoDBRepositoryContext.RegisterConventions(false, true);

            Mapper.CreateMap<Item, ItemData>();
            Mapper.CreateMap<ItemData, Item>();
            Mapper.CreateMap<Library, LibraryData>();
            Mapper.CreateMap<LibraryData, Library>();
            Mapper.CreateMap<Shop, ShopData>();
            Mapper.CreateMap<ShopData, Shop>();
            Mapper.CreateMap<User, UserData>();
            Mapper.CreateMap<UserData, User>();

            IocLocator.Container.RegisterType<IMongoDBSettings, DanrengMongoDBSettings>(eDbHost.Mongo_Main.ToString(), new ContainerControlledLifetimeManager());
            IocLocator.Container.RegisterType<IRepositoryContext, MongoDBRepositoryContext>(eDbType.Mongo.ToString(), new ContainerControlledLifetimeManager());

            IocLocator.Container.RegisterType<IRepository<Item>, MongoDBRepository<Item>>(eDbType.Mongo.ToString(), new HttpContextLife<IRepository<Item>>());
            IocLocator.Container.RegisterType<IRepository<Shop>, MongoDBRepository<Shop>>(eDbType.Mongo.ToString(), new HttpContextLife<IRepository<Shop>>());
            IocLocator.Container.RegisterType<IRepository<Library>, MongoDBRepository<Library>>(eDbType.Mongo.ToString(), new HttpContextLife<IRepository<Library>>());
            IocLocator.Container.RegisterType<IRepository<User>, MongoDBRepository<User>>(eDbType.Mongo.ToString(), new HttpContextLife<IRepository<User>>());

        }
    }
}